'use strict';
const db = uniCloud.database()
const dbCmd = db.command
exports.main = async (event, context) => {
  const flag = event.flag
  if (flag === 0) { //查看今天是否已打开
    const {
      id,
      openTime
    } = event
    return await db.collection("attendance").where({
      id,
      openTime: dbCmd.gte(openTime)
    }).get()
  } else if (flag === 1) {
    const {
      id,
      openTime
    } = event
    return await db.collection("attendance").add({
      id,
      openTime
    })
  } else if (flag === 2) {
    const {
      id,
    } = event
    return await db.collection("attendance").where({
      id
    }).count()
  }

};